home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pascal Super Library
/
Pascal Super Library (CW International)(1997).bin
/
DELPHI32
/
MATH
/
PI
/
PI.ZIP
/
MAIN.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-06-17
|
3KB
|
119 lines
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, Buttons, ComCtrls;
const
// Change this value to get more digits
PI_LIMIT = 2500;
type
TPiForm = class(TForm)
CalculatingNameLabel: TLabel;
PiProgressBar: TProgressBar;
CloseBitBtn: TBitBtn;
AbortBitBtn: TBitBtn;
StartNameLabel: TLabel;
ProcessNameLabel: TLabel;
CalculatingLabel: TLabel;
Start18Label: TLabel;
FinishTimeLabel: TLabel;
OkBitBtn: TBitBtn;
PiTimer: TTimer;
Label1: TLabel;
Start57Label: TLabel;
Label3: TLabel;
Start239Label: TLabel;
Label2: TLabel;
StartPILabel: TLabel;
procedure CloseBitBtnClick(Sender: TObject);
procedure AbortBitBtnClick(Sender: TObject);
procedure OkBitBtnClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure PiTimerTimer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
PiForm: TPiForm;
implementation
uses pidata, arctan;
{$R *.DFM}
procedure TPiForm.CloseBitBtnClick(Sender: TObject);
begin
Close;
end;
procedure TPiForm.AbortBitBtnClick(Sender: TObject);
begin
PiDataModule.cancel_operation:= True;
end;
procedure TPiForm.OkBitBtnClick(Sender: TObject);
var
calculate_pi: TCalculatePi;
begin
// Construct a Pi class
calculate_pi.Create(PI_LIMIT);
// Set the maximum limit of the progress bar
PiProgressBar.Max:= PI_LIMIT;
// Calculate the arctangent of 1/18
CalculatingLabel.Caption:= 'ArcTan 1/18';
Start18Label.Caption:= DateTimeToStr(Now);
Application.ProcessMessages;
calculate_pi.ArcTan(18);
// Calculate the arctangent of 1/57
CalculatingLabel.Caption:= 'ArcTan 1/57';
Start57Label.Caption:= DateTimeToStr(Now);
Application.ProcessMessages;
calculate_pi.ArcTan(57);
// Calculate the arctangent of 1/239
CalculatingLabel.Caption:= 'ArcTan 1/239';
Start239Label.Caption:= DateTimeToStr(Now);
Application.ProcessMessages;
calculate_pi.ArcTan(239);
// And then sum it all up
CalculatingLabel.Caption:= 'Computing PI';
StartPILabel.Caption:= DateTimeToStr(Now);
Application.ProcessMessages;
calculate_pi.Sum;
// And tidy up now that we have finished
CalculatingLabel.Caption:= 'Finished';
PiProgressBar.Position:= 0;
PiDataModule.start_position:= 0;
FinishTimeLabel.Caption:= DateTimeToStr(Now);
Application.ProcessMessages;
// Could someone tell my why I get an exception when I un-comment the
// following line. I would have assumed that the Free was necessary?
// calculate_pi.Free;
end;
procedure TPiForm.FormCreate(Sender: TObject);
begin
CalculatingLabel.Caption:= '';
Start18Label.Caption:= '';
Start57Label.Caption:= '';
Start239Label.Caption:= '';
StartPILabel.Caption:= '';
FinishTimeLabel.Caption:= '';
end;
procedure TPiForm.PiTimerTimer(Sender: TObject);
begin
PiProgressBar.Position:= PiDataModule.start_position;
Application.ProcessMessages;
end;
end.